AngularJS by Brad Green & Shyam Seshadri

AngularJS by Brad Green & Shyam Seshadri

Author:Brad Green & Shyam Seshadri
Language: eng
Format: epub
Tags: COMPUTERS / Internet / Application Development
ISBN: 9781449344849
Publisher: O’Reilly Media
Published: 2013-04-09T04:00:00+00:00


With that harness in place, let’s take a look at the unit tests for the List Controller:

describe('ListCtrl', function() { var mockBackend, recipe; // _$httpBackend_ is the same as $httpBackend. Only written this way to // differentiate between injected variables and local variables beforeEach(inject(function($rootScope, $controller, _$httpBackend_, Recipe) { recipe = Recipe; mockBackend = _$httpBackend_; $scope = $rootScope.$new(); ctrl = $controller('ListCtrl', { $scope: $scope, recipes: [1, 2, 3] }); })); it('should have list of recipes', function() { expect($scope.recipes).toEqual([1, 2, 3]); }); });

Remember that the List Controller is one of the simplest controllers we have. The constructor of the controller just takes in a list of recipes and saves it to the scope. You could write a test for it, but it seems kind of silly (we still did it, because tests are awesome!).

Instead, the more interesting aspect is the MultiRecipeLoader service. This is responsible for fetching the list of recipes from the server and passing it in as an argument (when hooked up correctly via the $route service):



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.